#ifndef UTIL_H
#define UTIL_H

#include "xercesc/framework/MemoryManager.hpp"
#include "xercesc/util/XMLString.hpp"
#include "XmlDefs.h"


namespace xerces {

class StrX
{
 public :
  // -----------------------------------------------------------------------
  //  Constructors and Destructor
  // -----------------------------------------------------------------------
  StrX(const XMLCh* const toTranscode)
    {
      if(toTranscode)
	// Call the private transcoding method
	fLocalForm = XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(toTranscode);
      else
	fLocalForm = NULL;
    }
  
 StrX() : fLocalForm( NULL ) {}

  ~StrX()
    {
      if(fLocalForm)
	XERCES_CPP_NAMESPACE_QUALIFIER XMLString::release(&fLocalForm);
    }
  
  
  // -----------------------------------------------------------------------
  //  Getter methods
  // -----------------------------------------------------------------------
  const char* localForm() const
    {
      return fLocalForm;
    }
  
 private :
  // -----------------------------------------------------------------------
  //  Private data members
  //
  //  fLocalForm
  //      This is the local code page form of the string.
  // -----------------------------------------------------------------------
  char*   fLocalForm;
};

class XStr
{
 public :
  // -----------------------------------------------------------------------
  //  Constructors and Destructor
  // -----------------------------------------------------------------------
  XStr(const char* const toTranscode)
    {
      if(toTranscode)
	// Call the private transcoding method
	fUnicodeForm = XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(toTranscode);
      else
	fUnicodeForm = NULL;
    }
  
 XStr() : fUnicodeForm( NULL ) {}

  ~XStr()
    {
      if(fUnicodeForm)
	XERCES_CPP_NAMESPACE_QUALIFIER XMLString::release(&fUnicodeForm);
    }
  
  
  // -----------------------------------------------------------------------
  //  Getter methods
  // -----------------------------------------------------------------------
  const XMLCh* unicodeForm() const
    {
      return fUnicodeForm;
    }
  
 private :
  // -----------------------------------------------------------------------
  //  Private data members
  //
  //  fUnicodeForm
  //      This is the Unicode XMLCh format of the string.
  // -----------------------------------------------------------------------
  XMLCh*   fUnicodeForm;
};

#define StrtoX(str) xerces::XStr(str).unicodeForm()
#define XtoStr(m)   xerces::StrX(m).localForm()
 

}; // end of namespace xerces

#endif
